<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >

<head>
    <th:block th:include="include :: header('医废出库')" />
    <link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link href="../static/css/main/animate.min.css" th:href="@{/css/main/animate.min.css}" rel="stylesheet"/>
    <link href="../static/css/main/style.min862f.css" th:href="@{/css/main/style.min862f.css}" rel="stylesheet"/>
</head>

<body>


<div class="main-content">


    <div class="form-horizontal">

        <div class="row" style="margin-top:30px">                    <!--  "value=value.replace(/[^\d]/g,'')"  -->
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label" style="font-size:18px;color:#638ED3;" >请扫描医废条码：</label>
                    <div class="col-sm-8">
                        <input id="scancodeid" name="scancodeid" class="form-control" oninput = "checkBarcode(this)"
                               value="" placeholder="请扫描医废条码"  type="text" maxlength="22" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="row" style="margin-top:50px">
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label" style="font-size:18px;color:#638ED3;">上次扫描的条码：</label>
                    <div class="col-sm-8">
                        <input id="lastcodeid" name="lastcodeid" class="form-control"
                               value="" placeholder="上次扫描的条码"  type="text" maxlength="22"  autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label" style="font-size:18px;color:#638ED3;">当前状态：</label>
                    <label id="currentStatus" name="currentStatus" style="margin-top:7px;font-size:18px;color:#f5222d;"></label>
                </div>
            </div>
        </div>

    </div>



    <div class="form-horizontal">

        <h4 class="form-header h4" style="margin-top:50px;margin-left:30px;margin-right:30px;font-size:18px;color:#638ED3;">医废信息</h4>

        <div class="row" style="margin-top:50px">
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">医废条码：</label>
                    <div class="col-sm-8">
                        <input id="codeid" name="codeid" class="form-control" placeholder=""  type="text" maxlength="30" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">产生科室：</label>
                    <div class="col-sm-8">
                        <input id="sourceDeptName" name="sourceDeptName" placeholder="" class="form-control" type="text"
                               maxlength="30" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="row" style="margin-top:30px">
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">医废类型：</label>
                    <div class="col-sm-8">
                        <input id="trashTypeName" name="trashTypeName" placeholder="" class="form-control" type="text" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">医废重量：</label>
                    <div class="col-sm-8">
                        <input id="weight" name="weight" class="form-control" type="text" maxlength="20" placeholder="" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="row" style="margin-top:30px">
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">收集人员：</label>
                    <div class="col-sm-8">
                        <input id="collectUserName" name="collectUserName" placeholder="" class="form-control" type="text" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">收集时间：</label>
                    <div class="col-sm-8">
                        <input id="collectUpdateDate" name="collectUpdateDate" placeholder="" class="form-control" type="text"
                               maxlength="30" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="row" style="margin-top:30px">
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">转运人员：</label>
                    <div class="col-sm-8">
                        <input id="transUserName" name="transUserName" placeholder="" class="form-control" type="text" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">转运时间：</label>
                    <div class="col-sm-8">
                        <input id="transDate" name="transDate" placeholder="" class="form-control" type="text"
                               maxlength="30" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="row" style="margin-top:30px">
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">入库人员：</label>
                    <div class="col-sm-8">
                        <input id="intoUserName" name="intoUserName" placeholder="" class="form-control" type="text" autocomplete="off">
                    </div>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label">入库时间：</label>
                    <div class="col-sm-8">
                        <input id="intoDate" name="intoDate" placeholder="" class="form-control" type="text"
                               maxlength="30" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

    </div>


</div>



<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.js}"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>

<script type="text/javascript">

    // xiaomeng  音量：8   其它：默认
    var audio = document.createElement("audio");

    $(function() {

    });

    // 医废条码输入框获取焦点
    $("#scancodeid").focus();


    // 条形码输入事件
    function checkBarcode(barcode){
        // 只能输入数字
        barcode.value = barcode.value.replace(/[^\d]/g,'');
        console.log(barcode.value);
        // 22位时先验证
        if( barcode.value.length == 22 ){
            var code = barcode.value;
            // 条码输入框先失去焦点
            $("#scancodeid").blur();
            // 22位时条形码装到 上次扫描的条码，扫描条码框置空
            $("#lastcodeid").val(code);
            $("#scancodeid").val('');

            // alert( code + '');

            // 提示框
            parent.$.modal.loading("正在查询...");

            $.ajax({
                type : "post",
                url : parent.ctx + "client/data/barcode/validation",
                data : {"pcode": code},
                // contentType:"application/json",
                // dataType : "json",
                success : function(res) {     //  code  0 成功  500 失败    msg   data
                    parent.$.modal.closeLoading();
                    if( res.code == 0 ){
                        // 根据条码查询医废信息
                        getYFByBarcode(code);
                    }else if( res.code == 500 ){
                        $("#currentStatus").html( "条形码无效" );
                        audio.src = "../mp3/tiaomawuxiao.mp3";
                        audio.play();
                        // 把医废信息置空、扫描框获取焦点
                        setNullYFInfo();
                    }else {
                        $("#currentStatus").html( "条形码无效" );
                        audio.src = "../mp3/tiaomawuxiao.mp3";
                        audio.play();
                        // 把医废信息置空、扫描框获取焦点
                        setNullYFInfo();
                    }
                },
                error:function(res){
                    parent.$.modal.closeLoading();
                    $("#currentStatus").html( "请检查网络" );
                    audio.src = "../mp3/checknet.mp3";
                    audio.play();
                    // 扫描框获取焦点
                    $("#scancodeid").focus();
                }

            });

        }

    }


    // 根据条码查询医废信息
    function getYFByBarcode(barcode){
        $.ajax({
            type : "post",
            url : parent.ctx + "client/report/getYFInfoByBarcodeAndStagingId",
            data : {
                "codeId": barcode,
                "stagingId": 500012
            },
            success : function(res) {
                parent.$.modal.closeLoading();

                // 如果是入库状态则可以出库
                if( res.trashStatus == '20' ){
                    $("#codeid").val(res.codeid);
                    $("#sourceDeptName").val(res.sourceDeptName);
                    $("#trashTypeName").val(res.trashTypeName);
                    $("#weight").val(res.weight + ' kg');
                    $("#collectUserName").val(res.collectUserName);
                    $("#collectUpdateDate").val(res.collectUpdateDate);
                    $("#transUserName").val(res.transUserName);
                    $("#transDate").val(res.transDate);
                    $("#intoUserName").val(res.intoUserName);
                    $("#intoDate").val(res.intoDate);

                    // 医废 入库  ->  出库
                    YFOutStore(barcode,570);
                }else if( res.trashStatus == '10' ){
                    $("#currentStatus").html( "医废未转运" );
                    audio.src = "../mp3/yifeiweizhuanyun.mp3";
                    audio.play();
                    // 把医废信息置空、扫描框获取焦点
                    setNullYFInfo();
                }else if( res.trashStatus == '15' ){
                    $("#currentStatus").html("医废未入库");
                    audio.src = "../mp3/yifeiweiruku.mp3";
                    audio.play();
                    // 把医废信息置空、扫描框获取焦点
                    setNullYFInfo();
                }else if( res.trashStatus == '30' ){
                    $("#currentStatus").html("医废已出库");
                    audio.src = "../mp3/yifeiyichuku.mp3";
                    audio.play();
                    // 把医废信息置空、扫描框获取焦点
                    setNullYFInfo();
                }else{
                    // $("#currentStatus").html("医废状态异常");
                    // audio.src = "../mp3/yifeistatusyich.mp3";
                    $("#currentStatus").html( "医废条码无效" );
                    audio.src = "../mp3/yifeicodewuxiao.mp3";
                    audio.play();
                    // 把医废信息置空、扫描框获取焦点
                    setNullYFInfo();
                }

            },
            error:function(res){
                parent.$.modal.closeLoading();
                $("#currentStatus").html( "医废条码无效" );
                audio.src = "../mp3/yifeicodewuxiao.mp3";
                audio.play();
                // 把医废信息置空、扫描框获取焦点
                setNullYFInfo();
            }

        });

    }


    // 把医废信息置空、扫描框获取焦点
    function setNullYFInfo(){
        $("#codeid").val('');
        $("#sourceDeptName").val('');
        $("#trashTypeName").val('');
        $("#weight").val('');
        $("#collectUserName").val('');
        $("#collectUpdateDate").val('');
        $("#transUserName").val('');
        $("#transDate").val('');
        $("#intoUserName").val('');
        $("#intoDate").val('');
        // 扫描框获取焦点
        $("#scancodeid").focus();
    }


    // 医废 入库  ->  出库
    function YFOutStore(barcode,userId){
        parent.$.modal.loading("正在出库...");
        $.ajax({
            type : "post",
            url : parent.ctx + "client/report/inStoreToOutStoreYF",
            data : {"codeId": barcode,"userId":userId},
            success : function(res) {
                parent.$.modal.closeLoading();

                if( res.resultCode == "Y" ){
                    // parent.$.modal.msgSuccess( res.msg );
                    $("#currentStatus").html( "出库成功" );
                    audio.src = "../mp3/chukuchenggong.mp3";
                    audio.play();
                    // 扫描框获取焦点
                    $("#scancodeid").focus();
                }else {
                    $("#currentStatus").html( "出库失败" );
                    audio.src = "../mp3/chukushibai.mp3";
                    audio.play();
                    // 扫描框获取焦点
                    $("#scancodeid").focus();
                }

            },
            error:function(res){
                parent.$.modal.closeLoading();
                $("#currentStatus").html( "出库异常" );
                audio.src = "../mp3/chukuyichang.mp3";
                audio.play();
                // 扫描框获取焦点
                $("#scancodeid").focus();
            }

        });
    }


</script>


</body>

</html>